<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/10/27
 * Time: 10:16
 */

namespace zhtfrontend\modules\sitepadapi\controllers;

use zhtfrontend\models\datas\OrdercourseHistory;
use zhtfrontend\models\datas\OrderSales;
use zhtfrontend\models\datas\Sales;
use zhtfrontend\modules\sitepadapi\components\rest\ActiveController;
use yii\data\ActiveDataProvider;
use yii\web\Response;

class CommentcustomerController extends ActiveController
{
    public $modelClass = 'common\models\datas\Customer';

    public $serializer = [
        'class' => 'zhtfrontend\modules\sitepadapi\components\rest\Serializer',
        'collectionEnvelope' => 'items',
    ];

    public function behaviors()
    {
        $behaviors = parent::behaviors();
        $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
        return $behaviors;
    }

    public function actions()
    {
        $actions = parent::actions();
        unset($actions['index'], $actions['create'], $actions['update'], $actions['delete'], $actions['view']);
        return $actions;
    }

    public function actionIndex()
    {
        $modelClass = $this->modelClass;
        $query = $modelClass::find();
        return new ActiveDataProvider([
            'query' => $query
        ]);
    }

    public function actionFindbytid($teacher_id){
        $sales_id=Sales::find()->select('id')->where(['teacher_id'=>$teacher_id])->asArray()->column();
        $order_sales_id=OrderSales::find()->select('id')->where(['in','sales_id',$sales_id])->asArray()->column();
        $customer_id=OrdercourseHistory::find()->select('user_id')->where(['order_sales_id'=>$order_sales_id])->asArray()->column();
        $modelClass=$this->modelClass;
        $query=$modelClass::find()->where(['in','id',$customer_id]);
        return new ActiveDataProvider([
            'query'=>$query
        ]);
    }

    public function actionCreate(){

    }
}